<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>zapmenot.model &mdash; Zapmenot 0.1 documentation</title>
      <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    <script src="../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
            <a href="../../index.html" class="icon icon-home"> Zapmenot
          </a>
              <div class="version">
                0.1
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../license.html">Licence &amp; Disclaimer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../materials.html">Material Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../isotopes.html">Isotope Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modeling.html">Modeling in ZapMeNot</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../results.html">Generating Results</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../graphics.html">We Want Pictures!</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../theory-and-methods.html">Theory and Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../benchmarks.html">Benchmarking</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../module-docs.html">Module Contents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../developer.html">Developer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../version-history.html">Version History</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">Zapmenot</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home"></a></li>
          <li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
      <li class="breadcrumb-item active">zapmenot.model</li>
      <li class="wy-breadcrumbs-aside">
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <h1>Source code for zapmenot.model</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">numbers</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">ray</span><span class="p">,</span> <span class="n">material</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">shield</span><span class="p">,</span> <span class="n">detector</span>

<span class="kn">import</span> <span class="nn">importlib</span>
<span class="n">pyvista_spec</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">find_spec</span><span class="p">(</span><span class="s2">&quot;pyvista&quot;</span><span class="p">)</span>
<span class="n">pyvista_found</span> <span class="o">=</span> <span class="n">pyvista_spec</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">pyvista</span>


<div class="viewcode-block" id="Model"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model">[docs]</a><span class="k">class</span> <span class="nc">Model</span><span class="p">:</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Performs point-kernel shielding analysis.</span>

<span class="sd">    The Model class combines various shielding elements to perform</span>
<span class="sd">    the point-kernel photon shielding analysis.  These elements include</span>
<span class="sd">    sources, shields, and detectors.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    source : :class:`zapmenot.source.Source`</span>
<span class="sd">        The source distribution (point, line, or volume) included in the model.</span>

<span class="sd">    shield_list : :class:`list` of :class:`zapmenot.shield.Shield`</span>
<span class="sd">        A list of shields (including the source volume) contained in the model.</span>

<span class="sd">    detector : :class:`zapmenot.detector.Detector`</span>
<span class="sd">        The single detector in the model used to determine the exposure.</span>

<span class="sd">    filler_material : :class:`zapmenot.material.Material`</span>
<span class="sd">        The (optional) material used as fill around the formal shields.</span>

<span class="sd">    buildup_factor_material : :class:`zapmenot.material.Material`</span>
<span class="sd">        The material used to calculate the exposure buildup factor.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">source</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">detector</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filler_material</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">buildup_factor_material</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="c1"># used to calculate exposure (R/sec) from flux (photon/cm2 sec),</span>
        <span class="c1"># photon energy (MeV),</span>
        <span class="c1"># and linear energy absorption coeff (cm2/g)</span>
        <span class="c1"># aka, &quot;flux to exposure conversion factor&quot;</span>
        <span class="c1"># for more information, see &quot;Radiation Shielding&quot;, J. K. Shultis</span>
        <span class="c1">#  and R.E. Faw, 2000, page 141.</span>
        <span class="c1"># This value is based on a value of energy deposition</span>
        <span class="c1"># per ion in air of 33.85 [ICRU Report 39, 1979].</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_conversion_factor</span> <span class="o">=</span> <span class="mf">1.835E-8</span>

<div class="viewcode-block" id="Model.set_filler_material"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model.set_filler_material">[docs]</a>    <span class="k">def</span> <span class="nf">set_filler_material</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filler_material</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Set the filler material used by the model</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        filler_material : str</span>
<span class="sd">            The material to be used.</span>
<span class="sd">        density : float, optional</span>
<span class="sd">            The density of the material in g/cm\ :sup:`3`.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">filler_material</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid filler material&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filler_material</span> <span class="o">=</span> <span class="n">material</span><span class="o">.</span><span class="n">Material</span><span class="p">(</span><span class="n">filler_material</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">density</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">density</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid density: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">density</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">filler_material</span><span class="o">.</span><span class="n">density</span> <span class="o">=</span> <span class="n">density</span></div>

<div class="viewcode-block" id="Model.add_source"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model.add_source">[docs]</a>    <span class="k">def</span> <span class="nf">add_source</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_source</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Set the source used by the model.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        new_source : :class:`zapmenot.source.Source`</span>
<span class="sd">            The source to be used.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">new_source</span><span class="p">,</span> <span class="n">source</span><span class="o">.</span><span class="n">Source</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid source&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">source</span> <span class="o">=</span> <span class="n">new_source</span>
        <span class="c1"># don&#39;t forget that sources are shields too!</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_source</span><span class="p">)</span></div>

<div class="viewcode-block" id="Model.add_shield"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model.add_shield">[docs]</a>    <span class="k">def</span> <span class="nf">add_shield</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_shield</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Add a shield to the collection of shields used by the model.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        new_shield : :class:`zapmenot.shield.Shield`</span>
<span class="sd">            The shield to be added.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">new_shield</span><span class="p">,</span> <span class="n">shield</span><span class="o">.</span><span class="n">Shield</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid shield&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_shield</span><span class="p">)</span></div>

<div class="viewcode-block" id="Model.add_detector"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model.add_detector">[docs]</a>    <span class="k">def</span> <span class="nf">add_detector</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_detector</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Set the detector used by the model.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        new_detector : :class:`zapmenot.detector.Detector`</span>
<span class="sd">            The detector to be used in the model.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">new_detector</span><span class="p">,</span> <span class="n">detector</span><span class="o">.</span><span class="n">Detector</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid detector&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">detector</span> <span class="o">=</span> <span class="n">new_detector</span></div>

<div class="viewcode-block" id="Model.set_buildup_factor_material"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model.set_buildup_factor_material">[docs]</a>    <span class="k">def</span> <span class="nf">set_buildup_factor_material</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_material</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Set the material used to calculation exposure buildup factors.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        new_material : :class:`zapmenot.material.Material`</span>
<span class="sd">            The material to be used in buildup factor calculations.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">new_material</span><span class="p">,</span> <span class="n">material</span><span class="o">.</span><span class="n">Material</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid buildup factor material&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">buildup_factor_material</span> <span class="o">=</span> <span class="n">new_material</span></div>

<div class="viewcode-block" id="Model.calculate_exposure"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model.calculate_exposure">[docs]</a>    <span class="k">def</span> <span class="nf">calculate_exposure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the exposure at the detector location.</span>

<span class="sd">        Note:  Significant use of Numpy arrays to speed up evaluating the</span>
<span class="sd">        dose from each source point.  A &quot;for loop&quot; is used to loop</span>
<span class="sd">        through photon energies, but many of the iterations through</span>
<span class="sd">        all source points is performed using matrix math.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        float</span>
<span class="sd">            The exposure in units of mR/hr.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">results_by_photon_energy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_summary</span><span class="p">()</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">results_by_photon_energy</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="mi">0</span>  <span class="c1"># may occur if source has no photons</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">results_by_photon_energy</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">results_by_photon_energy</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">4</span><span class="p">]</span>  <span class="c1"># mR/hr</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># sum exposure over all photons</span>
            <span class="n">an_array</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">results_by_photon_energy</span><span class="p">)</span>
            <span class="n">integral_results</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">an_array</span><span class="p">[:,</span> <span class="mi">4</span><span class="p">])</span>
            <span class="k">return</span> <span class="n">integral_results</span>  <span class="c1"># mR/hr</span></div>

<div class="viewcode-block" id="Model.generate_summary"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model.generate_summary">[docs]</a>    <span class="k">def</span> <span class="nf">generate_summary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the energy flux and exposure at the detector location.</span>

<span class="sd">        Note:  Significant use of Numpy arrays to speed up evaluating the</span>
<span class="sd">        dose from each source point.  A &quot;for loop&quot; is used to loop</span>
<span class="sd">        through photon energies, but many of the iterations through</span>
<span class="sd">        all source points is performed using matrix math.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`list`</span>
<span class="sd">            List, by photon energy, of photon energy, photon emmission rate,</span>
<span class="sd">            uncollided energy flux, uncollided exposure, and total exposure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># build an array of shield crossing lengths.</span>
        <span class="c1"># The first index is the source point.</span>
        <span class="c1"># The second index is the shield (including the source body).</span>
        <span class="c1"># The total transit distance in the &quot;filler&quot; material (if any)</span>
        <span class="c1"># is determined by subtracting the sum of the shield crossing</span>
        <span class="c1"># lengths from the total ray length.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">source</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Model is missing a source&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">detector</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Model is missing a detector&quot;</span><span class="p">)</span>
        <span class="n">source_points</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">_get_source_points</span><span class="p">()</span>
        <span class="n">source_point_weights</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">_get_source_point_weights</span><span class="p">()</span>
        <span class="n">crossing_distances</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">source_points</span><span class="p">),</span>
                                       <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span><span class="p">)))</span>
        <span class="n">total_distance</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">source_points</span><span class="p">)))</span>
        <span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">nextPoint</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">source_points</span><span class="p">):</span>
            <span class="n">vector</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">FiniteLengthRay</span><span class="p">(</span><span class="n">nextPoint</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">location</span><span class="p">)</span>
            <span class="n">total_distance</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="o">=</span> <span class="n">vector</span><span class="o">.</span><span class="n">_length</span>
            <span class="c1"># check to see if source point and detector are coincident</span>
            <span class="k">if</span> <span class="n">total_distance</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;detector and source are coincident&quot;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">index2</span><span class="p">,</span> <span class="n">thisShield</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span><span class="p">):</span>
                <span class="n">crossing_distances</span><span class="p">[</span><span class="n">index</span><span class="p">,</span> <span class="n">index2</span><span class="p">]</span> <span class="o">=</span> \
                    <span class="n">thisShield</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">vector</span><span class="p">)</span>
        <span class="n">gaps</span> <span class="o">=</span> <span class="n">total_distance</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">crossing_distances</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">amin</span><span class="p">(</span><span class="n">gaps</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Looks like shields and/or sources overlap&quot;</span><span class="p">)</span>

        <span class="n">results_by_photon_energy</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># get a list of photons (energy &amp; intensity) from the source</span>
        <span class="n">spectrum</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">get_photon_source_list</span><span class="p">()</span>

        <span class="n">air</span> <span class="o">=</span> <span class="n">material</span><span class="o">.</span><span class="n">Material</span><span class="p">(</span><span class="s1">&#39;air&#39;</span><span class="p">)</span>

        <span class="c1"># iterate through the photon list</span>
        <span class="k">for</span> <span class="n">photon</span> <span class="ow">in</span> <span class="n">spectrum</span><span class="p">:</span>
            <span class="n">photon_energy</span> <span class="o">=</span> <span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="c1"># photon source strength</span>
            <span class="n">photon_yield</span> <span class="o">=</span> <span class="n">photon</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

            <span class="n">dose_coeff</span> <span class="o">=</span> <span class="n">air</span><span class="o">.</span><span class="n">get_mass_energy_abs_coeff</span><span class="p">(</span><span class="n">photon_energy</span><span class="p">)</span>

            <span class="c1"># determine the xsecs</span>
            <span class="n">xsecs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span><span class="p">)))</span>
            <span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">thisShield</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span><span class="p">):</span>
                <span class="n">xsecs</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="o">=</span> <span class="n">thisShield</span><span class="o">.</span><span class="n">material</span><span class="o">.</span><span class="n">density</span> <span class="o">*</span> \
                    <span class="n">thisShield</span><span class="o">.</span><span class="n">material</span><span class="o">.</span><span class="n">get_mass_atten_coeff</span><span class="p">(</span><span class="n">photon_energy</span><span class="p">)</span>
            <span class="c1"># determine an array of mean free paths, one per source point</span>
            <span class="n">total_mfp</span> <span class="o">=</span> <span class="n">crossing_distances</span> <span class="o">*</span> <span class="n">xsecs</span>
            <span class="n">total_mfp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">total_mfp</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
            <span class="c1"># add the gaps if required</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">filler_material</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">gap_xsec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">filler_material</span><span class="o">.</span><span class="n">density</span> <span class="o">*</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">filler_material</span><span class="o">.</span><span class="n">get_mass_atten_coeff</span><span class="p">(</span><span class="n">photon_energy</span><span class="p">)</span>
                <span class="n">total_mfp</span> <span class="o">=</span> <span class="n">total_mfp</span> <span class="o">+</span> <span class="p">(</span><span class="n">gaps</span> <span class="o">*</span> <span class="n">gap_xsec</span><span class="p">)</span>
            <span class="n">uncollided_flux_factor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">total_mfp</span><span class="p">)</span>
            <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">buildup_factor_material</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">):</span>
                <span class="n">buildup_factor</span> <span class="o">=</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">buildup_factor_material</span><span class="o">.</span><span class="n">get_buildup_factor</span><span class="p">(</span>
                        <span class="n">photon_energy</span><span class="p">,</span> <span class="n">total_mfp</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">buildup_factor</span> <span class="o">=</span> <span class="mf">1.0</span>
            <span class="n">uncollided_point_energy_flux</span> <span class="o">=</span> <span class="n">photon_yield</span> <span class="o">*</span> \
                <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">source_point_weights</span><span class="p">)</span> \
                <span class="o">*</span> <span class="n">uncollided_flux_factor</span> <span class="o">*</span> <span class="n">photon_energy</span> <span class="o">*</span> \
                <span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="p">(</span><span class="mi">4</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">power</span><span class="p">(</span><span class="n">total_distance</span><span class="p">,</span> <span class="mi">2</span><span class="p">)))</span>
            <span class="n">total_uncollided_energy_flux</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">uncollided_point_energy_flux</span><span class="p">)</span>

            <span class="n">uncollided_point_exposure</span> <span class="o">=</span> <span class="n">uncollided_point_energy_flux</span> <span class="o">*</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">_conversion_factor</span> <span class="o">*</span> <span class="n">dose_coeff</span> <span class="o">*</span> <span class="mi">1000</span> <span class="o">*</span> <span class="mi">3600</span>  <span class="c1"># mR/hr</span>
            <span class="n">total_uncollided_exposure</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">uncollided_point_exposure</span><span class="p">)</span>

            <span class="n">collided_point_exposure</span> <span class="o">=</span> <span class="n">uncollided_point_exposure</span> <span class="o">*</span> \
                <span class="n">buildup_factor</span>
            <span class="n">total_collided_exposure</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">collided_point_exposure</span><span class="p">)</span>

            <span class="n">results_by_photon_energy</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="n">photon_energy</span><span class="p">,</span> <span class="n">photon_yield</span><span class="p">,</span> <span class="n">total_uncollided_energy_flux</span><span class="p">,</span>
                 <span class="n">total_uncollided_exposure</span><span class="p">,</span> <span class="n">total_collided_exposure</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">results_by_photon_energy</span></div>

<div class="viewcode-block" id="Model.display"><a class="viewcode-back" href="../../module-docs.html#zapmenot.model.Model.display">[docs]</a>    <span class="k">def</span> <span class="nf">display</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Produces a graphic display of the model.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
            <span class="c1"># find the bounding box for all objects</span>
            <span class="n">bounds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_findBoundingBox</span><span class="p">()</span>
            <span class="n">pl</span> <span class="o">=</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Plotter</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_trimBlocks</span><span class="p">(</span><span class="n">pl</span><span class="p">,</span> <span class="n">bounds</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_addPoints</span><span class="p">(</span><span class="n">pl</span><span class="p">)</span>
            <span class="n">pl</span><span class="o">.</span><span class="n">show_bounds</span><span class="p">(</span><span class="n">grid</span><span class="o">=</span><span class="s1">&#39;front&#39;</span><span class="p">,</span> <span class="n">location</span><span class="o">=</span><span class="s1">&#39;outer&#39;</span><span class="p">,</span> <span class="n">all_edges</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">pl</span><span class="o">.</span><span class="n">add_legend</span><span class="p">(</span><span class="n">face</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">))</span>
            <span class="n">pl</span><span class="o">.</span><span class="n">show</span><span class="p">()</span></div>

    <span class="k">def</span> <span class="nf">_trimBlocks</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pl</span><span class="p">,</span> <span class="n">bounds</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds shields to a Plotter instance after trimming any</span>
<span class="sd">        infinite shields to a predefined bounding box.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">shieldColor</span> <span class="o">=</span> <span class="s1">&#39;blue&#39;</span>
        <span class="n">sourceColor</span> <span class="o">=</span> <span class="s1">&#39;red&#39;</span>
        <span class="k">for</span> <span class="n">thisShield</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">thisShield</span><span class="o">.</span><span class="n">is_infinite</span><span class="p">():</span>
                <span class="n">clipped</span> <span class="o">=</span> <span class="n">thisShield</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
                <span class="n">clipped</span> <span class="o">=</span> <span class="n">clipped</span><span class="o">.</span><span class="n">clip_closed_surface</span><span class="p">(</span>
                    <span class="n">normal</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="p">[</span><span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
                <span class="n">clipped</span> <span class="o">=</span> <span class="n">clipped</span><span class="o">.</span><span class="n">clip_closed_surface</span><span class="p">(</span>
                    <span class="n">normal</span><span class="o">=</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mi">0</span><span class="p">])</span>
                <span class="n">clipped</span> <span class="o">=</span> <span class="n">clipped</span><span class="o">.</span><span class="n">clip_closed_surface</span><span class="p">(</span>
                    <span class="n">normal</span><span class="o">=</span><span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">4</span><span class="p">]])</span>
                <span class="n">clipped</span> <span class="o">=</span> <span class="n">clipped</span><span class="o">.</span><span class="n">clip_closed_surface</span><span class="p">(</span>
                    <span class="n">normal</span><span class="o">=</span><span class="s1">&#39;-x&#39;</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="p">[</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
                <span class="n">clipped</span> <span class="o">=</span> <span class="n">clipped</span><span class="o">.</span><span class="n">clip_closed_surface</span><span class="p">(</span>
                    <span class="n">normal</span><span class="o">=</span><span class="s1">&#39;-y&#39;</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="mi">0</span><span class="p">])</span>
                <span class="n">clipped</span> <span class="o">=</span> <span class="n">clipped</span><span class="o">.</span><span class="n">clip_closed_surface</span><span class="p">(</span>
                    <span class="n">normal</span><span class="o">=</span><span class="s1">&#39;-z&#39;</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">5</span><span class="p">]])</span>
                <span class="n">pl</span><span class="o">.</span><span class="n">add_mesh</span><span class="p">(</span><span class="n">clipped</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">shieldColor</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">thisShield</span><span class="p">,</span> <span class="n">source</span><span class="o">.</span><span class="n">Source</span><span class="p">):</span>
                    <span class="c1"># point sources are handled later</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">_get_source_points</span><span class="p">())</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                        <span class="n">pl</span><span class="o">.</span><span class="n">add_mesh</span><span class="p">(</span><span class="n">thisShield</span><span class="o">.</span><span class="n">draw</span><span class="p">(),</span> 
                                    <span class="n">sourceColor</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;source&#39;</span><span class="p">,</span> <span class="n">line_width</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">pl</span><span class="o">.</span><span class="n">add_mesh</span><span class="p">(</span><span class="n">thisShield</span><span class="o">.</span><span class="n">draw</span><span class="p">(),</span> <span class="n">shieldColor</span><span class="p">)</span>
        <span class="c1"># now add the &quot;bounds&quot; as a transparent block to for a display size</span>
        <span class="n">mesh</span> <span class="o">=</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Box</span><span class="p">(</span><span class="n">bounds</span><span class="p">)</span>
        <span class="n">pl</span><span class="o">.</span><span class="n">add_mesh</span><span class="p">(</span><span class="n">mesh</span><span class="p">,</span> <span class="n">opacity</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_findBoundingBox</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates a bounding box is X, Y, Z geometry that</span>
<span class="sd">        includes the volumes of all shields, the source, and the detector</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">blocks</span> <span class="o">=</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">MultiBlock</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">thisShield</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">shield_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">thisShield</span><span class="o">.</span><span class="n">is_infinite</span><span class="p">():</span>
                <span class="c1"># add finite shields to the MultiBlock composite</span>
                <span class="n">blocks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">thisShield</span><span class="o">.</span><span class="n">draw</span><span class="p">())</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># for infinete shield bodies,</span>
                <span class="c1"># project the detector location onto the infinite surface</span>
                <span class="c1"># to get points to add to the geometry</span>
                <span class="n">points</span> <span class="o">=</span> <span class="n">thisShield</span><span class="o">.</span><span class="n">_projection</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">x</span><span class="p">,</span>
                                                <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">y</span><span class="p">,</span>
                                                <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">z</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">point</span> <span class="ow">in</span> <span class="n">points</span><span class="p">:</span>
                    <span class="c1"># we are appending a degenerate line as a representation</span>
                    <span class="c1"># of a point</span>
                    <span class="n">blocks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pyvista</span><span class="o">.</span><span class="n">Line</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">point</span><span class="p">))</span>

        <span class="c1"># &gt;&gt;&gt;aren&#39;t all sources also shields?  Then the next line is redundant</span>
        <span class="c1"># TODO: figure out if the next line is necessary</span>
        <span class="c1"># blocks.append(self.source.draw())</span>

        <span class="c1"># include the detector geometry in the MultiBlock composite</span>
        <span class="n">blocks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">draw</span><span class="p">())</span>

        <span class="c1"># check for a zero width bounding box in any direction</span>
        <span class="n">bounds</span> <span class="o">=</span> <span class="n">blocks</span><span class="o">.</span><span class="n">bounds</span>
        <span class="n">x_width</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">y_width</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">-</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
        <span class="n">z_width</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="o">-</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span>
        <span class="n">max_width</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">x_width</span><span class="p">,</span> <span class="n">y_width</span><span class="p">,</span> <span class="n">z_width</span><span class="p">)</span>
        <span class="c1"># define a minimum dimension as 20% of the maximum dimension</span>
        <span class="n">min_width</span> <span class="o">=</span> <span class="n">max_width</span> <span class="o">*</span> <span class="mf">0.20</span>
        <span class="c1"># check for dimensions smaller than the defined minimum</span>
        <span class="k">if</span> <span class="n">x_width</span> <span class="o">&lt;</span> <span class="n">min_width</span><span class="p">:</span>
            <span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">min_width</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">min_width</span><span class="o">/</span><span class="mi">2</span>
        <span class="k">if</span> <span class="n">y_width</span> <span class="o">&lt;</span> <span class="n">min_width</span><span class="p">:</span>
            <span class="n">bounds</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="n">min_width</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">bounds</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">+</span> <span class="n">min_width</span><span class="o">/</span><span class="mi">2</span>
        <span class="k">if</span> <span class="n">z_width</span> <span class="o">&lt;</span> <span class="n">min_width</span><span class="p">:</span>
            <span class="n">bounds</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">=</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">-</span> <span class="n">min_width</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">bounds</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="o">=</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="o">+</span> <span class="n">min_width</span><span class="o">/</span><span class="mi">2</span>
        <span class="c1"># increase the display bounds by a smidge to avoid</span>
        <span class="c1">#   inadvertent clipping</span>
        <span class="n">boundingBox</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="o">*</span> <span class="mf">1.01</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">bounds</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">boundingBox</span>

    <span class="k">def</span> <span class="nf">_addPoints</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pl</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        the goal here is to add &#39;points&#39; to the display, but they</span>
<span class="sd">        must be represented as spheres to have some physical</span>
<span class="sd">        volume to display.  Points will be displayed with a radius</span>
<span class="sd">        of 5% of the smallest dimension of the bounding box.</span>

<span class="sd">        A problem can occur if the bounding box has a width of 0 in one</span>
<span class="sd">        or more of three dimensions.  An exception is thrown if bounds</span>
<span class="sd">        in all three directions are of zero width.  Otherwise the zero</span>
<span class="sd">        is ignored and the next largest dimension is used to size the</span>
<span class="sd">        point representation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">point_ratio</span> <span class="o">=</span> <span class="mf">0.05</span>
        <span class="n">sourceColor</span> <span class="o">=</span> <span class="s1">&#39;red&#39;</span>
        <span class="n">detectorColor</span> <span class="o">=</span> <span class="s1">&#39;yellow&#39;</span>
        <span class="n">widths</span> <span class="o">=</span> <span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">pl</span><span class="o">.</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">pl</span><span class="o">.</span><span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
                  <span class="nb">abs</span><span class="p">(</span><span class="n">pl</span><span class="o">.</span><span class="n">bounds</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">-</span> <span class="n">pl</span><span class="o">.</span><span class="n">bounds</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                  <span class="nb">abs</span><span class="p">(</span><span class="n">pl</span><span class="o">.</span><span class="n">bounds</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="o">-</span> <span class="n">pl</span><span class="o">.</span><span class="n">bounds</span><span class="p">[</span><span class="mi">4</span><span class="p">])]</span>
        <span class="n">good_widths</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">width</span> <span class="ow">in</span> <span class="n">widths</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">width</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">good_widths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">good_widths</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;detector and source are coincident&quot;</span><span class="p">)</span>
        <span class="c1"># determine a good radius for the points</span>
        <span class="n">point_radius</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">good_widths</span><span class="p">)</span> <span class="o">*</span> <span class="n">point_ratio</span>
        <span class="c1"># check if the source is a point source</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">_get_source_points</span><span class="p">())</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">body</span> <span class="o">=</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Sphere</span><span class="p">(</span><span class="n">center</span><span class="o">=</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">_x</span><span class="p">,</span>
                                          <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">_y</span><span class="p">,</span>
                                          <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">_z</span><span class="p">),</span>
                                  <span class="n">radius</span><span class="o">=</span><span class="n">point_radius</span><span class="p">)</span>
            <span class="n">pl</span><span class="o">.</span><span class="n">add_mesh</span><span class="p">(</span>
                <span class="n">body</span><span class="p">,</span> <span class="n">line_width</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">sourceColor</span><span class="p">,</span>
                <span class="n">label</span><span class="o">=</span><span class="s1">&#39;source&#39;</span><span class="p">)</span>
        <span class="n">body</span> <span class="o">=</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Sphere</span><span class="p">(</span><span class="n">center</span><span class="o">=</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">x</span><span class="p">,</span>
                                      <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">y</span><span class="p">,</span>
                                      <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">z</span><span class="p">),</span>
                              <span class="n">radius</span><span class="o">=</span><span class="n">point_radius</span><span class="p">)</span>
        <span class="n">pl</span><span class="o">.</span><span class="n">add_mesh</span><span class="p">(</span>
            <span class="n">body</span><span class="p">,</span> <span class="n">line_width</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">detectorColor</span><span class="p">,</span>
            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;detector&#39;</span><span class="p">)</span></div>
        <span class="c1"># pl.set_background(color=&#39;white&#39;)</span>
</pre></div>

           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2019 - 2023, Alan Ford..
      <span class="lastupdated">Last updated on Feb 12, 2023.
      </span></p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>